package cn.sunline.dreamvalue.utils;

import cn.sunline.dreamvalue.constant.ResultStatus;
import cn.sunline.dreamvalue.exception.DreamValueExcption;
import cn.sunline.dreamvalue.service.impl.DreamValueServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.util.Date;


/**
 * @title: DreamDateUtilities
 * @projectName dream-value
 * @description: 时间校验类
 * @author 82345
 * @date 2020/5/19 13:57
 */
public class DreamDateUtil {
    public static final Logger log = LoggerFactory.getLogger(DreamDateUtil.class);

    /**
     　* @description: 校验时间格式是否正确
     　* @param [str]
     　* @return boolean
     　* @author 11292
     　* @date 2020/5/21 23:26
     */
    public static boolean isValidDateTime(String str) {
        boolean convertSuccess=true;
        //日期格式
        DateTimeFormatter formatter = new DateTimeFormatterBuilder()
                // 解析date+time
                .appendPattern("yyyyMMddHHmmss")
                // 解析毫秒数
                .appendValue(ChronoField.MILLI_OF_SECOND, 2)
                .toFormatter();
        try{
            ZoneId zone = ZoneId.systemDefault();
            LocalDateTime dateTime = LocalDateTime.parse(str,formatter);
            Instant instant = dateTime.atZone(zone).toInstant();
            Date transDate = Date.from(instant);
        }catch (Exception e){
            log.error("调增格式化时间时发生异常：{}",e.getMessage());
            convertSuccess = false;
        }
        return convertSuccess;
    }

}
